#!/usr/bin/python3
# by Sun Smallwhite <niasw@pku.edu.cn>(https://github.com/niasw)

import sw.io.loadCSV
import sw.io.loadTSV
import sw.io.saveJSON
import sw.io.loadJSON
import sw.io.adaptor
import scipy.sparse
import numpy

def transWebOfScience(filename,src='json'):
  '''
# Read WebOfScience Citation Data
# src: origin/json
  '''
  if (src=='origin'):
    print('Loading '+'../dat/'+filename);
    data=sw.io.loadTSV.webOfScience('../dat/'+filename);
    sw.io.saveJSON.saveJSON('../out/'+filename+'.json',data);
    sw.io.adaptor.webOfSciNode2csvMat(data,dtype='data',extname=filename);
  elif (src=='json'):
    print('Loading '+'../out/'+filename);
    sw.io.adaptor.webOfSciNode2csvMat(filename,dtype='file');
  else:
    raise(Exception('Warning: invalid src: '+src+'.'));

if (__name__=='__main__'):
  '''
# python adaptWebOfScience.py filename src='json'
  '''
  import sys
  args=[None,'','json'];
  for it in range(0,len(sys.argv)):
    args[it]=sys.argv[it];
  transWebOfScience(args[1],args[2]);
